//
//  HisDetailCell.swift
//  ShouChong
//
//  Created by yw on 2024/9/18.
//

import UIKit

class HisDetailCell: UITableViewCell {
    
    @IBOutlet weak var heartRateLabel: UILabel!
    @IBOutlet weak var countLabel: UILabel!
    
    @IBOutlet weak var durationLabel: UILabel!
    
    
    @IBOutlet weak var createTimeLabel: UILabel!
    
    @IBOutlet weak var isWatchImage: UIImageView!
    
    @IBOutlet weak var feelingImage: UIImageView!
    @IBOutlet weak var heartImage: UIImageView!
    
    @IBOutlet weak var timeImage: UIImageView!
    var model:HistoryModel?{
        didSet {
            if let mdoels = model {
                self.countLabel.text = mdoels.count
                self.heartRateLabel.text =  mdoels.duration
                self.durationLabel.text = mdoels.heartRate
                if mdoels.isWatch == "1" {
                    self.isWatchImage.isHidden = false
                    self.isWatchImage.image = UIImage(systemName: "applewatch")
                } else {
                    self.isWatchImage.isHidden = true
                }
                self.createTimeLabel.text = mdoels.createTime
                if mdoels.remark == "-1" {
                    self.feelingImage.isHidden = true
                } else{
                    self.feelingImage.isHidden = false
                    if model?.remark == "1000" {
                        self.feelingImage.image = UIImage(named: "feeling_01")
                    } else if model?.remark == "1001" {
                        self.feelingImage.image = UIImage(named: "feeling_02")
                    } else if model?.remark == "1002" {
                        self.feelingImage.image = UIImage(named: "feeling_03")
                    }
                }
            }
            
        }
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.layer.cornerRadius = 20
        self.clipsToBounds = true
        self.timeImage.image = UIImage.systemImage(systemName: "clock.fill", tintColor: UIColor(named: GetMainColorTool.getMainColor()) ?? .colorBg)
        self.heartImage.image = UIImage.systemImage(systemName: "heart.fill", tintColor: UIColor(named: GetMainColorTool.getMainColor()) ?? .colorBg)
    }
    
    class func createHisDetailView(tableView:UITableView,index:IndexPath) -> HisDetailCell {
        
        var cell = tableView.dequeueReusableCell(withIdentifier: "HisDetailCellID", for: index) as? HisDetailCell
        if cell == nil {
            cell = Bundle.main.loadNibNamed("HisDetailCell", owner: nil)?.last as? HisDetailCell
        }
        return cell!
    }
    
    override var frame: CGRect{
        didSet {
            var newFrame = frame
            newFrame.origin.x += 10
            newFrame.size.width -= newFrame.origin.x * 2
            newFrame.origin.y += 10
            newFrame.size.height -= 10
            super.frame = newFrame
        }
    }
    
    
}
